package com.yfp.operation.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yfp.operation.domain.MarActivity;
import com.yfp.operation.domain.dto.ActivityDTO;
import com.yfp.operation.domain.vo.ActivityVO;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 *
 * @description 针对表【mar_activity(活动)】的数据库操作Mapper
 * @createDate 2024-07-16 16:11:30
 * @Entity domain.com.yfp.operation.MarActivity
 */
public interface MarActivityMapper extends BaseMapper<MarActivity> {

    /**
     * 新增
     *
     * @param marActivity
     */
    void add(MarActivity marActivity);

    /**
     * 活动列表
     *
     * @param activityDTO
     * @return
     */
    List<ActivityVO> marActivityList(ActivityDTO activityDTO);

    /**
     * 修改状态
     *
     * @param marActivityId
     * @param status
     */
    void updateStatus(@Param("marActivityId") Long marActivityId, @Param("status") Integer status);

    /**
     * 调用存储过程
     *
     * <pre>{@code
     * CREATE OR REPLACE PROCEDURE "public"."update_mar_activity_status"()
     *  AS $BODY$
     * DECLARE
     *     r RECORD;
     * BEGIN
     *     FOR r IN SELECT * FROM mar_activity WHERE "status"=1 LOOP
     *         -- 如果end_time小于当前时间，更新status
     *         IF r.end_time < NOW() THEN
     *             UPDATE mar_activity
     *             SET status = 2 -- 2表示过期状态
     *             WHERE id = r.id;
     *         END IF;
     *     END LOOP;
     *
     * 		FOR r IN SELECT * FROM mar_activity WHERE "status"=4 LOOP
     *         -- 如果start_time大于等于当前时间 and 当前时间小于等于end_time更新status
     *         IF NOW() >= r.start_time and NOW() <= r.end_time THEN
     *             UPDATE mar_activity
     *             SET status = 1 -- 1表示正常状态
     *             WHERE id = r.id;
     *         END IF;
     *     END LOOP;
     * END;
     * $BODY$
     *   LANGUAGE plpgsql
     * }</pre>
     */
    // @Select("call update_mar_activity_status()")
    void callUpdateMarActivityStatus();

    /**
     * 根据被动用户id和类型查询活动
     *
     * @param passiveClientId
     * @param type
     * @return
     */
    MarActivity selectByPassiveClientIdAndType(@Param("passiveClientId") String passiveClientId, @Param("type") int type);

    /**
     * 修改活动
     * @param marActivity
     */
    void updateActivity(MarActivity marActivity);

}




